<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="算法,回溯法,子集树,排列树," />










<meta name="description" content="等式全排序排列：  从n个数中选取m（m&lt;&#x3D;n）个数按照一定的顺序进行排成一个列，叫作从n个元素中取m个元素的一个排列。不同的顺序是一个不同的排列。从n个元素中取m个元素的所有排列的个数，称为排列数。 全排列：  从n个元素取出n个元素的一个排列，称为一个全排列。全排列的排列数公式为n!时间复杂度： n个数的全排列有n!种，每一个排列都有n个数据，所以输出的时间复杂度为O(n*n!)，呈指数">
<meta property="og:type" content="article">
<meta property="og:title" content="疑难问题">
<meta property="og:url" content="http://yangshucheng2020.gitee.io/blog/2020/03/27/%E7%96%91%E9%9A%BE%E9%97%AE%E9%A2%98/index.html">
<meta property="og:site_name" content="羊书">
<meta property="og:description" content="等式全排序排列：  从n个数中选取m（m&lt;&#x3D;n）个数按照一定的顺序进行排成一个列，叫作从n个元素中取m个元素的一个排列。不同的顺序是一个不同的排列。从n个元素中取m个元素的所有排列的个数，称为排列数。 全排列：  从n个元素取出n个元素的一个排列，称为一个全排列。全排列的排列数公式为n!时间复杂度： n个数的全排列有n!种，每一个排列都有n个数据，所以输出的时间复杂度为O(n*n!)，呈指数">
<meta property="og:image" content="http://yangshucheng2020.gitee.io/Users/yangshucheng/Documents/2020%E5%A4%8D%E8%AF%95/%E5%A1%AB%E7%A9%BA.jpg">
<meta property="og:image" content="http://yangshucheng2020.gitee.io/blog/2020/03/27/%E7%96%91%E9%9A%BE%E9%97%AE%E9%A2%98/%E7%96%91%E9%9A%BE%E9%97%AE%E9%A2%98.assets/IMG_20200311_122706.jpg">
<meta property="article:published_time" content="2020-03-27T02:59:07.022Z">
<meta property="article:modified_time" content="2020-03-27T04:38:18.388Z">
<meta property="article:author" content="羊书">
<meta property="article:tag" content="算法">
<meta property="article:tag" content="回溯法">
<meta property="article:tag" content="子集树">
<meta property="article:tag" content="排列树">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yangshucheng2020.gitee.io/Users/yangshucheng/Documents/2020%E5%A4%8D%E8%AF%95/%E5%A1%AB%E7%A9%BA.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yangshucheng2020.gitee.io/blog/2020/03/27/疑难问题/"/>





  <title>疑难问题 | 羊书</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">羊书</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yangshucheng2020.gitee.io/blog/blog/2020/03/27/%E7%96%91%E9%9A%BE%E9%97%AE%E9%A2%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="羊书">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="羊书">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">疑难问题</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-27T10:59:07+08:00">
                2020-03-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index">
                    <span itemprop="name">学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="等式全排序"><a href="#等式全排序" class="headerlink" title="等式全排序"></a>等式全排序</h2><h3 id="排列："><a href="#排列：" class="headerlink" title="排列："></a>排列：</h3><p>  从n个数中选取m（m&lt;=n）个数按照一定的顺序进行排成一个列，叫作从n个元素中取m个元素的一个排列。不同的顺序是一个不同的排列。从n个元素中取m个元素的所有排列的个数，称为排列数。</p>
<h3 id="全排列："><a href="#全排列：" class="headerlink" title="全排列："></a>全排列：</h3><p>  从n个元素取出n个元素的一个排列，称为一个全排列。全排列的排列数公式为n!<br>时间复杂度：</p>
<pre><code>n个数的全排列有n!种，每一个排列都有n个数据，所以输出的时间复杂度为O(n*n!)，呈指数级，无法处理大型数据。</code></pre><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> N 4</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">int</span> n[<span class="number">100</span>];</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; num_v, renum;</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">char</span>&gt; char_v, rechar;</span><br><span class="line"><span class="keyword">int</span> max_len = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">double</span> re;</span><br><span class="line"><span class="keyword">char</span> oper[N] = &#123; <span class="string">'/'</span>, <span class="string">'*'</span>, <span class="string">'-'</span>, <span class="string">'+'</span>&#125;;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">seq</span><span class="params">(<span class="keyword">int</span> m,<span class="keyword">int</span> k, <span class="keyword">int</span> len, <span class="keyword">double</span> sum)</span> </span>&#123;<span class="comment">//k为利用的数字的位数</span></span><br><span class="line">    <span class="keyword">if</span> (sum == re ) &#123;<span class="comment">//如果当前计算结果sum=re要求的结果并且第一次满足，则跳出递归，保存结果</span></span><br><span class="line">        renum = num_v;          <span class="comment">//数字结果存入renum</span></span><br><span class="line">        rechar = char_v;        <span class="comment">//字符结果存入rechar</span></span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; m &lt;&lt;<span class="string">" "</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; rechar.<span class="built_in">size</span>() ; ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span>( i &lt; renum.<span class="built_in">size</span>())&#123;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; rechar[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; renum[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (k &gt;= len) <span class="keyword">return</span>;       <span class="comment">//k大于总长度时，退出递归，表示找不到正确的结果</span></span><br><span class="line">    num_v.push_back(n[k]);      <span class="comment">//将第k位数字加入num_v</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;<span class="comment">//对字符进行选择，先往符号数组加入，再递归调用</span></span><br><span class="line">        <span class="keyword">char</span> op = oper[i];</span><br><span class="line">        <span class="keyword">if</span> (op == <span class="string">'+'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'+'</span>);</span><br><span class="line">            seq(m,k + <span class="number">1</span>, len, sum + n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'*'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'*'</span>);</span><br><span class="line">            seq(m,k + <span class="number">1</span>, len, sum * n[k]);</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'-'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'-'</span>);</span><br><span class="line">            seq(m,k + <span class="number">1</span>, len, sum - n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'/'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'/'</span>);</span><br><span class="line">            seq(m,k + <span class="number">1</span>, len, sum / n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        char_v.pop_back();<span class="comment">//都试过却不可以得出正确结果则把符号弹出</span></span><br><span class="line">    &#125;</span><br><span class="line">    num_v.pop_back();</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> len;</span><br><span class="line">    <span class="keyword">double</span> m;<span class="comment">//m 小明手上牌的数字， re 运算结果的要求  ，len  桌上牌的个数</span></span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">"%lf %lf %d"</span>, &amp;m, &amp;re, &amp;len);</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; len; i++)<span class="comment">// 桌上牌的数字</span></span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;n[i]);</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">double</span> sum = m;<span class="comment">//sum为当前的计算结果</span></span><br><span class="line">    seq(m, k, len, sum);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> 本程序利用回溯法</span></span><br><span class="line"><span class="comment"> 输入5 13 6 1 3 9 4 2 2</span></span><br><span class="line"><span class="comment"> 输出</span></span><br><span class="line"><span class="comment"> 5 / 1 / 3 * 9 - 4 + 2</span></span><br><span class="line"><span class="comment"> 5 / 1 * 3 - 9 * 4 + 2 / 2</span></span><br><span class="line"><span class="comment"> 5 / 1 * 3 + 9 + 4 - 2 / 2</span></span><br><span class="line"><span class="comment"> 5 / 1 - 3 * 9 / 4 + 2 * 2</span></span><br><span class="line"><span class="comment"> 5 / 1 - 3 * 9 + 4 / 2 + 2</span></span><br><span class="line"><span class="comment"> 5 / 1 - 3 + 9 + 4 - 2</span></span><br><span class="line"><span class="comment"> 等等全部从5（小明的牌） 开始 尽可能到后面的结果</span></span><br><span class="line"><span class="comment"> 请问拓展一下：</span></span><br><span class="line"><span class="comment">    ① 将包括所有能成立的等式，数字只要是 牌的数字（即 5 13 6 1 3 9 4 2 2里面任意选择多个 可以相连的数字 也可以不相连） 组成所有满足结果的等式应该怎么写</span></span><br><span class="line"><span class="comment">    ② 我预想用一个结构体来处理写出 所有满足结果的等式中最长最短的所有等式 ，思想就是：</span></span><br><span class="line"><span class="comment"> struct myEqu&#123;</span></span><br><span class="line"><span class="comment">    string equ;//存储等式</span></span><br><span class="line"><span class="comment">    int k;     //数字的个数</span></span><br><span class="line"><span class="comment">    bool operator &lt;(const myEqu &amp;a)const&#123;</span></span><br><span class="line"><span class="comment">        return k &lt; a.k;</span></span><br><span class="line"><span class="comment"> &#125;</span></span><br><span class="line"><span class="comment">    bool operator &gt;(const myEqu &amp;a)const&#123;</span></span><br><span class="line"><span class="comment">        return k &gt; a.k;</span></span><br><span class="line"><span class="comment"> &#125;</span></span><br><span class="line"><span class="comment"> &#125;myEqu[100]</span></span><br><span class="line"><span class="comment">    先将所有等式存储在myEqu中，然后分别sort()排序一下，这样就排好最长和最短等式了，最后输出即可</span></span><br><span class="line"><span class="comment"> */</span></span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> N 4</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">int</span> n[<span class="number">100</span>];</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; num_v, renum;</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">char</span>&gt; char_v, rechar;</span><br><span class="line"><span class="keyword">int</span> max_len = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">double</span> re;</span><br><span class="line"><span class="keyword">char</span> oper[N] = &#123; <span class="string">'/'</span>, <span class="string">'*'</span>, <span class="string">'-'</span>, <span class="string">'+'</span> &#125;;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">cal</span><span class="params">(<span class="keyword">int</span> k,<span class="keyword">int</span> m,<span class="keyword">int</span> sum,<span class="keyword">int</span> len)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">seq</span><span class="params">(<span class="keyword">int</span> m, <span class="keyword">int</span> k, <span class="keyword">int</span> len, <span class="keyword">double</span> sum)</span> </span>&#123;</span><br><span class="line">    <span class="comment">//k为利用的数字的位数</span></span><br><span class="line">    <span class="keyword">if</span> (sum == re) &#123;<span class="comment">//如果当前计算结果sum=re要求的结果，则跳出递归，保存结果</span></span><br><span class="line">        renum = num_v;          <span class="comment">//数字结果存入renum</span></span><br><span class="line">        rechar = char_v;        <span class="comment">//字符结果存入rechar</span></span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; m &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; rechar.<span class="built_in">size</span>(); ++i) &#123;<span class="comment">//输出结果</span></span><br><span class="line">            <span class="keyword">if</span> (i &lt; renum.<span class="built_in">size</span>()) &#123;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; rechar[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; renum[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">if</span> (k &gt;= len) <span class="keyword">return</span>;<span class="comment">//如果k大于所给数字的总长度，则跳出</span></span><br><span class="line">       <span class="comment">// cal(k, m, sum, len);//如果还有数字没有使用到，则计算等于re 的剩下数字构成的表达式</span></span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (k &gt;= len) <span class="keyword">return</span>; <span class="comment">//k大于总长度时，退出递归，表示找不到正确的结果</span></span><br><span class="line">    seq(m, k + <span class="number">1</span>, len, sum);<span class="comment">//当还有数字需要利用，并且结果不满足条件的时候，继续递归</span></span><br><span class="line">    cal(k,m,sum,len);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">cal</span><span class="params">(<span class="keyword">int</span> k,<span class="keyword">int</span> m,<span class="keyword">int</span> sum,<span class="keyword">int</span> len)</span></span>&#123;<span class="comment">//第k位数字开始，首元素是m，当前算式结果是sum，当前数字数组总长度为len</span></span><br><span class="line">    num_v.push_back(n[k]);      <span class="comment">//将第k位数字加入num_v</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;<span class="comment">//对字符进行选择，先往符号数组加入，再递归调用</span></span><br><span class="line">        <span class="keyword">char</span> op = oper[i];</span><br><span class="line">        <span class="keyword">if</span> (op == <span class="string">'+'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'+'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum + n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'*'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'*'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum * n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'-'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'-'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum - n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'/'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'/'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum / n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        char_v.pop_back();<span class="comment">//都试过却不可以得出正确结果则把符号弹出</span></span><br><span class="line">    &#125;</span><br><span class="line">    num_v.pop_back();</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> len;</span><br><span class="line">    <span class="keyword">double</span> m;<span class="comment">//m 小明手上牌的数字， re 运算结果的要求  ，len  桌上牌的个数</span></span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">"%lf %lf %d"</span>, &amp;m, &amp;re, &amp;len);</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; len; i++)<span class="comment">// 桌上牌的数字</span></span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;n[i]);</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;<span class="comment">//k为从桌上的第k张牌开始</span></span><br><span class="line">    <span class="keyword">double</span> sum = m;<span class="comment">//sum为当前的计算结果</span></span><br><span class="line">    seq(m, k, len, sum);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> N 4</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">int</span> n[<span class="number">100</span>];</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; num_v, renum;</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">char</span>&gt; char_v, rechar;</span><br><span class="line"><span class="keyword">int</span> max_len = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">double</span> re;</span><br><span class="line"><span class="keyword">char</span> oper[N] = &#123; <span class="string">'/'</span>, <span class="string">'*'</span>, <span class="string">'-'</span>, <span class="string">'+'</span> &#125;;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">seq</span><span class="params">(<span class="keyword">int</span> m, <span class="keyword">int</span> k, <span class="keyword">int</span> len, <span class="keyword">double</span> sum)</span> </span>&#123;</span><br><span class="line">    <span class="comment">//k为利用的数字的位数</span></span><br><span class="line">    <span class="keyword">if</span> (sum == re) &#123;<span class="comment">//如果当前计算结果sum=re要求的结果并且第一次满足，则跳出递归，保存结果</span></span><br><span class="line">        renum = num_v;          <span class="comment">//数字结果存入renum</span></span><br><span class="line">        rechar = char_v;        <span class="comment">//字符结果存入rechar</span></span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; m &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; rechar.<span class="built_in">size</span>(); ++i) &#123;</span><br><span class="line">            <span class="keyword">if</span> (i &lt; renum.<span class="built_in">size</span>()) &#123;</span><br><span class="line">                <span class="built_in">cout</span> &lt;&lt; rechar[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; renum[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">if</span> (k &gt;= len) <span class="keyword">return</span>;</span><br><span class="line">        num_v.push_back(n[k]);      <span class="comment">//将第k位数字加入num_v</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;<span class="comment">//对字符进行选择，先往符号数组加入，再递归调用</span></span><br><span class="line">            <span class="keyword">char</span> op = oper[i];</span><br><span class="line">            <span class="keyword">if</span> (op == <span class="string">'+'</span>) &#123;</span><br><span class="line">                char_v.push_back(<span class="string">'+'</span>);</span><br><span class="line">                seq(m, k + <span class="number">1</span>, len, sum + n[k]);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'*'</span>) &#123;</span><br><span class="line">                char_v.push_back(<span class="string">'*'</span>);</span><br><span class="line">                seq(m, k + <span class="number">1</span>, len, sum * n[k]);</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'-'</span>) &#123;</span><br><span class="line">                char_v.push_back(<span class="string">'-'</span>);</span><br><span class="line">                seq(m, k + <span class="number">1</span>, len, sum - n[k]);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'/'</span>) &#123;</span><br><span class="line">                char_v.push_back(<span class="string">'/'</span>);</span><br><span class="line">                seq(m, k + <span class="number">1</span>, len, sum / n[k]);</span><br><span class="line">            &#125;</span><br><span class="line">            char_v.pop_back();<span class="comment">//都试过却不可以得出正确结果则把符号弹出</span></span><br><span class="line">        &#125;</span><br><span class="line">        num_v.pop_back();</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (k &gt;= len) <span class="keyword">return</span>;      <span class="comment">//k大于总长度时，退出递归，表示找不到正确的结果</span></span><br><span class="line"></span><br><span class="line">    seq(m, k + <span class="number">1</span>, len, sum);</span><br><span class="line"></span><br><span class="line">    num_v.push_back(n[k]);      <span class="comment">//将第k位数字加入num_v</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;<span class="comment">//对字符进行选择，先往符号数组加入，再递归调用</span></span><br><span class="line">        <span class="keyword">char</span> op = oper[i];</span><br><span class="line">        <span class="keyword">if</span> (op == <span class="string">'+'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'+'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum + n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'*'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'*'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum * n[k]);</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'-'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'-'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum - n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'/'</span>) &#123;</span><br><span class="line">            char_v.push_back(<span class="string">'/'</span>);</span><br><span class="line">            seq(m, k + <span class="number">1</span>, len, sum / n[k]);</span><br><span class="line">        &#125;</span><br><span class="line">        char_v.pop_back();<span class="comment">//都试过却不可以得出正确结果则把符号弹出</span></span><br><span class="line">    &#125;</span><br><span class="line">    num_v.pop_back();</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> len;</span><br><span class="line">    <span class="keyword">double</span> m;<span class="comment">//m 小明手上牌的数字， re 运算结果的要求  ，len  桌上牌的个数</span></span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">"%lf %lf %d"</span>, &amp;m, &amp;re, &amp;len);</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; len; i++)<span class="comment">// 桌上牌的数字</span></span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;n[i]);</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">double</span> sum = m;<span class="comment">//sum为当前的计算结果</span></span><br><span class="line">    seq(m, k, len, sum);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="1-2-3-4-5-6-7-8-9-110"><a href="#1-2-3-4-5-6-7-8-9-110" class="headerlink" title="1 2 3 4 5 6 7 8 9 = 110"></a>1 2 3 4 5 6 7 8 9 = 110</h2><p><img src="/Users/yangshucheng/Documents/2020%E5%A4%8D%E8%AF%95/%E5%A1%AB%E7%A9%BA.jpg" alt=""></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">int</span> a[<span class="number">9</span>] = &#123; <span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span> &#125;;</span><br><span class="line"><span class="comment">//将数字间的空格看做符号，扫描到空格则合并，扫描到符号则计算，共有3^8种数字组合形式</span></span><br><span class="line"><span class="keyword">char</span> c[N] = &#123; <span class="string">'+'</span>,<span class="string">'-'</span>,<span class="string">' '</span> &#125;;</span><br><span class="line"><span class="keyword">int</span> ans = <span class="number">110</span>;</span><br><span class="line"><span class="built_in">vector</span>&lt;<span class="keyword">char</span>&gt; equs;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">joint</span><span class="params">(<span class="keyword">int</span> old,<span class="keyword">int</span> right)</span></span>&#123;<span class="comment">//拼接old与right</span></span><br><span class="line">    <span class="keyword">int</span> newnum = old*<span class="number">10</span> + right;</span><br><span class="line">    <span class="keyword">return</span> newnum;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//枚举所有的符号</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">cal</span><span class="params">(<span class="keyword">int</span> k, <span class="keyword">int</span> len)</span> </span>&#123;<span class="comment">//k为当前扫描的数字的位数，len为数组中间的可填充符号个数</span></span><br><span class="line">    <span class="keyword">if</span> (k &gt;= len) &#123;</span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">0</span>, j = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> left = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">int</span> right;</span><br><span class="line">        <span class="keyword">char</span> op = <span class="string">'+'</span>;</span><br><span class="line">        <span class="keyword">while</span> (i &lt;= equs.<span class="built_in">size</span>()) &#123;</span><br><span class="line">            <span class="keyword">while</span> (i &lt; equs.<span class="built_in">size</span>() &amp;&amp; equs[i] == <span class="string">' '</span>)i++;</span><br><span class="line">            right = a[j];</span><br><span class="line">            <span class="keyword">while</span> (j &lt; i) &#123;</span><br><span class="line">                right = joint(right, a[j + <span class="number">1</span>]);</span><br><span class="line">                j++;</span><br><span class="line">            &#125;<span class="comment">//如果遇到‘ ’则把两边的数字拼接起来，一个一个地拼接</span></span><br><span class="line">            <span class="keyword">if</span> (op == <span class="string">'+'</span>)&#123;</span><br><span class="line">                left += right;</span><br><span class="line">            &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">                left -= right;</span><br><span class="line">            &#125;</span><br><span class="line">                op = equs[i++];</span><br><span class="line">                j = i;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (left == ans) &#123;</span><br><span class="line">            <span class="built_in">cout</span>&lt;&lt;<span class="number">1</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; equs.<span class="built_in">size</span>(); i++) &#123;</span><br><span class="line">                <span class="keyword">if</span> (equs[i]!=<span class="string">' '</span>) &#123;</span><br><span class="line">                    <span class="built_in">cout</span> &lt;&lt; <span class="string">" "</span> &lt;&lt; equs[i] &lt;&lt; <span class="string">" "</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                    <span class="built_in">cout</span> &lt;&lt; a[i+<span class="number">1</span>];</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="built_in">cout</span> &lt;&lt; <span class="string">" = "</span> &lt;&lt; ans &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; N; i++) &#123;</span><br><span class="line"> <span class="comment">//先对各种符号进行枚举，全部压入equs里，对字符进行选择，先往符号数组加入，再递归调用</span></span><br><span class="line">        <span class="keyword">char</span> op = c[i];</span><br><span class="line">        <span class="keyword">if</span> (op == <span class="string">'+'</span>) &#123;</span><br><span class="line">            equs.push_back(<span class="string">'+'</span>);</span><br><span class="line">            cal(k + <span class="number">1</span>, len);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">'-'</span>) &#123;</span><br><span class="line">            equs.push_back(<span class="string">'-'</span>);</span><br><span class="line">            cal(k + <span class="number">1</span>, len);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (op == <span class="string">' '</span>) &#123;<span class="comment">//遇到空格，合并前一个（可能已经拼接的）数字与后一个数字两个数字</span></span><br><span class="line">            equs.push_back(<span class="string">' '</span>);</span><br><span class="line">            cal(k + <span class="number">1</span>, len);</span><br><span class="line">        &#125;</span><br><span class="line">        equs.pop_back();<span class="comment">//都试过却不可以得出正确结果则把符号弹出</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    cal(<span class="number">0</span>, <span class="number">8</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="删除不合法字符"><a href="#删除不合法字符" class="headerlink" title="删除不合法字符"></a>删除不合法字符</h2><p>现在有一串字符串由【（）】组成，请判断其是否括号匹配（。如果合法就输出合法，如果不合法就删除不合法的字符，使其成为合法字符串。</p>
<h3 id="C-从string中删除所有的某个特定字符"><a href="#C-从string中删除所有的某个特定字符" class="headerlink" title="C++从string中删除所有的某个特定字符"></a>C++从string中删除所有的某个特定字符</h3><p><strong>std::remove</strong><br>C++中要从string中删除所有某个特定字符， 除了自己写一个函数外，还可用如下代码：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">str.erase(<span class="built_in">std</span>::<span class="built_in">remove</span>(str.<span class="built_in">begin</span>(), str.<span class="built_in">end</span>(), <span class="string">'a'</span>), str.<span class="built_in">end</span>());</span><br></pre></td></tr></table></figure>

<p>其中, remove来自<algorithm>, 它的签名是</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span> &lt;<span class="class"><span class="keyword">class</span> <span class="title">ForwardIterator</span>, <span class="title">class</span> <span class="title">T</span>&gt;</span></span><br><span class="line"><span class="class">  <span class="title">ForwardIterator</span> <span class="title">remove</span> (<span class="title">ForwardIterator</span> <span class="title">first</span>, <span class="title">ForwardIterator</span> <span class="title">last</span>, <span class="title">const</span> <span class="title">T</span>&amp; <span class="title">val</span>);</span></span><br></pre></td></tr></table></figure>

<p>作用：为在容器中, 删除[first, last)之间的所有值等于val的值。删除方法：  将某个等于val的值用下一个不等于val的值覆盖。返回值:：一个迭代器 (记作newEnd), 该迭代器指向最后一个未被删除元素的下一个元素,  即相当于容器新的end。</p>
<p>所以, 运行完remove后， 容器的[first, newEnd)内的元素即为所有未被删除的元素， [newEnd, end)之间的元素已经没用了。这样， 再运行str.erase(newEnd, str.end())即可清空[newEnd, end)之间的元素。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstring&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stack&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;//remove函数来自algorithm头文件</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAXN = <span class="number">200</span>;</span><br><span class="line"><span class="keyword">int</span> a[MAXN];<span class="comment">//存储有错误的位置</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Equ</span>&#123;</span></span><br><span class="line">    <span class="keyword">int</span> x;<span class="comment">//坐标</span></span><br><span class="line">    <span class="keyword">char</span> c;<span class="comment">//字符</span></span><br><span class="line">    Equ(<span class="keyword">int</span> x,<span class="keyword">char</span> c):x(x),c(c)&#123;&#125;;</span><br><span class="line">    Equ()&#123;&#125;</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line">Equ equals[MAXN];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">cal</span><span class="params">(Equ equal[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="built_in">stack</span>&lt;Equ&gt; sta;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">        <span class="keyword">if</span> (equal[i].c == <span class="string">'('</span>) &#123;<span class="comment">//左括号入栈</span></span><br><span class="line">            sta.push(equal[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (equal[i].c== <span class="string">'['</span>) &#123;</span><br><span class="line">            sta.push(equal[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (equal[i].c== <span class="string">')'</span>) &#123;</span><br><span class="line">            <span class="keyword">if</span> (sta.empty()) &#123;<span class="comment">//如果一开始就是不匹配的，比如'))'就直接跳过</span></span><br><span class="line">                 a[i] = <span class="number">1</span>;</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="keyword">char</span> op = sta.top().c;</span><br><span class="line">            <span class="keyword">if</span> (op == <span class="string">'('</span>) &#123;</span><br><span class="line">                sta.pop();</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                a[i] = <span class="number">1</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">        <span class="keyword">if</span> (equal[i].c== <span class="string">']'</span>) &#123;</span><br><span class="line">            <span class="keyword">if</span> (!sta.empty()) &#123;</span><br><span class="line">                <span class="keyword">char</span> op = sta.top().c;</span><br><span class="line">                <span class="keyword">if</span> (op == <span class="string">'['</span>) &#123;</span><br><span class="line">                    sta.pop();</span><br><span class="line">                    <span class="keyword">continue</span>;</span><br><span class="line">                &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                    a[i] = <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                a[i] = <span class="number">1</span>;</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span> (!sta.empty()) &#123;</span><br><span class="line">        <span class="keyword">int</span> u = sta.top().x;</span><br><span class="line">        a[u] = <span class="number">1</span>;</span><br><span class="line">        sta.pop();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="built_in">string</span> s;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; <span class="string">"输入待匹配的等式"</span> &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    <span class="built_in">cin</span> &gt;&gt; s;</span><br><span class="line">    <span class="keyword">int</span> n = s.<span class="built_in">size</span>();</span><br><span class="line">    <span class="built_in">memset</span>(a, <span class="number">0</span>, <span class="keyword">sizeof</span>(a));</span><br><span class="line">    <span class="built_in">memset</span>(equals, <span class="number">0</span>, <span class="keyword">sizeof</span>(equals));</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">        equals[i] = Equ(i, s[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    cal(equals, n);</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; ++i) &#123;</span><br><span class="line">        <span class="keyword">if</span> (a[i] == <span class="number">1</span>) &#123;</span><br><span class="line">            s[i] = <span class="string">' '</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; s &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">    s.erase(<span class="built_in">remove</span>(s.<span class="built_in">begin</span>(), s.<span class="built_in">end</span>(), <span class="string">' '</span>), s.<span class="built_in">end</span>());<span class="comment">//删除‘ ’符号</span></span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt; s;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//)))((()()()()([][]</span></span><br></pre></td></tr></table></figure>



<h2 id="分发礼物"><a href="#分发礼物" class="headerlink" title="分发礼物"></a>分发礼物</h2><p><img src="%E7%96%91%E9%9A%BE%E9%97%AE%E9%A2%98.assets/IMG_20200311_122706.jpg" alt="IMG_20200311_122706"></p>
<p>思路：</p>
<ul>
<li>先把第一个小朋友礼物分好，有 r1 个不同的礼物</li>
<li>从第2个小朋友开始，分配礼物，需要看他与前一个小朋友的礼物不能够重合，优先从已经出现的但是前一个小朋友没有的礼物集合diff中进行选择，如果把集合选择完，礼物还是不够，那就分配全新的未出现的礼物，直到所需的个数满足要求</li>
<li>最后一个小朋友，不仅diff集合要和前一个小朋友比较，也要和第一个小朋友比较，与他们都不相同的礼物才能进入集合diff，随后继续利用diff集合分配礼物</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdio&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;algorithm&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;set&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAXN = <span class="number">200</span>;</span><br><span class="line"><span class="keyword">int</span> a[MAXN];</span><br><span class="line"><span class="built_in">set</span>&lt;<span class="keyword">int</span>&gt; gift[MAXN]; <span class="comment">//每个小朋友分到的礼物的编号</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> n;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"有几个小朋友需要礼物？"</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;n); <span class="comment">// n至少为2</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;a[i]); <span class="comment">// 每个小朋友需要的礼物数量</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">int</span> has_dist = <span class="number">0</span>; <span class="comment">//已经分配出去的礼物个数</span></span><br><span class="line">    <span class="built_in">set</span>&lt;<span class="keyword">int</span>&gt; am; <span class="comment">// 已经分配出去的礼物编号，每个礼物都不同，用set集合保证编号各不相同</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; a[<span class="number">0</span>]; i++) &#123;<span class="comment">//第一个小朋友获得礼物必须各不相同</span></span><br><span class="line">        am.insert(i + <span class="number">1</span>);</span><br><span class="line">        gift[<span class="number">0</span>].insert(i + <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    has_dist = a[<span class="number">0</span>];</span><br><span class="line">    <span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; diff; <span class="comment">// 存储所有分配出去礼物的编号集合与前一个小朋友分到礼物的编号集合的差集</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; n; i++) &#123;</span><br><span class="line">        <span class="keyword">int</span> temp = a[i];<span class="comment">//第i+1个小朋友得到的礼物数量</span></span><br><span class="line">        <span class="built_in">set</span>&lt;<span class="keyword">int</span>&gt; pre = gift[i - <span class="number">1</span>];<span class="comment">//前一个小朋友pre的礼物组成集合</span></span><br><span class="line">        <span class="function"><span class="built_in">vector</span>&lt;<span class="keyword">int</span>&gt; <span class="title">diff</span><span class="params">(<span class="number">1000</span>)</span></span>;<span class="comment">//存储与前一个小朋友不同的礼物并且其他小朋友已经有的礼物的集合</span></span><br><span class="line"><span class="comment">//默认初始化 diff的语句， 作用是 diff[0] = ... = diff[999] = 0;</span></span><br><span class="line"><span class="comment">//auto的原理就是根据后面的值，来自己推测前面的类型是什么。</span></span><br><span class="line"><span class="comment">//set_diference就是取集合差集用前面参数的集合减去后面参数的集合把结果存在最后一个vector里面</span></span><br><span class="line"><span class="comment">//用于求两个集合的差集，结果集合中包含所有属于第一个集合但不属于第二个集合的元素</span></span><br><span class="line">        <span class="comment">//iter为已经分配出去的编号集合减去前一个小朋友得到礼物集合的集合</span></span><br><span class="line">        <span class="keyword">auto</span> iter = set_difference(am.<span class="built_in">begin</span>(), am.<span class="built_in">end</span>(), pre.<span class="built_in">begin</span>(), pre.<span class="built_in">end</span>(), diff.<span class="built_in">begin</span>());</span><br><span class="line">        diff.resize(iter - diff.<span class="built_in">begin</span>());</span><br><span class="line"><span class="comment">//是把diff这个集合修整为刚刚好的大小,恰好保存与前一个小朋友不同但是其他小朋友已经有的礼物种类的集合</span></span><br><span class="line"><span class="comment">//1、resize(n)调整容器的长度大小，使其能容纳n个元素。如果n小于容器的当前的size，则删除多出来的元素。</span></span><br><span class="line"><span class="comment">//否则，添加采用值初始化的元素。</span></span><br><span class="line"><span class="comment">//2、resize(n，t)多一个参数t，将所有新添加的元素初始化为t。</span></span><br><span class="line">        <span class="keyword">if</span> (i == n - <span class="number">1</span>) &#123;<span class="comment">//分配到了最后一个小朋友，返回其他小朋友有但是第一个小朋友没有的礼物的集合</span></span><br><span class="line">            <span class="keyword">auto</span> iter = set_difference(diff.<span class="built_in">begin</span>(), diff.<span class="built_in">end</span>(),</span><br><span class="line">                                       gift[<span class="number">0</span>].<span class="built_in">begin</span>(), gift[<span class="number">0</span>].<span class="built_in">end</span>(),</span><br><span class="line">                                       diff.<span class="built_in">begin</span>());</span><br><span class="line">            diff.resize(iter - diff.<span class="built_in">begin</span>());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; diff.<span class="built_in">size</span>() &amp;&amp; temp &gt; <span class="number">0</span>; j++) &#123;</span><br><span class="line">            <span class="comment">//当j小于可能分配集合的大小，并且还需分配礼物的时候</span></span><br><span class="line">            <span class="comment">//向当前小朋友礼物集合中加入可能分配的礼物</span></span><br><span class="line">            gift[i].insert(diff[j]);</span><br><span class="line">            temp--;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">while</span> (temp--) &#123;<span class="comment">//当可能分配的礼物已经被分完的时候，添加全新的未出现的礼物</span></span><br><span class="line">            has_dist++;<span class="comment">//记录已经出现的礼物种类</span></span><br><span class="line">            am.insert(has_dist);<span class="comment">//往当前可分配礼物集合当中加入新礼物的编号</span></span><br><span class="line">            gift[i].insert(has_dist);<span class="comment">//往第i+1位小朋友中加入全新的礼物</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">"%d"</span>, has_dist);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/%E7%AE%97%E6%B3%95/" rel="tag"># 算法</a>
          
            <a href="/blog/tags/%E5%9B%9E%E6%BA%AF%E6%B3%95/" rel="tag"># 回溯法</a>
          
            <a href="/blog/tags/%E5%AD%90%E9%9B%86%E6%A0%91/" rel="tag"># 子集树</a>
          
            <a href="/blog/tags/%E6%8E%92%E5%88%97%E6%A0%91/" rel="tag"># 排列树</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2020/03/27/%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E9%A2%84%E5%A4%87%E7%9F%A5%E8%AF%86/" rel="next" title="算法设计预备知识">
                <i class="fa fa-chevron-left"></i> 算法设计预备知识
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2020/03/27/Eclipse%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C/" rel="prev" title="Eclipse基本操作">
                Eclipse基本操作 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">羊书</p>
              <p class="site-description motion-element" itemprop="description">记录生活</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/%7C%7Carchive">
              
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yangshucheng1219" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:ysc714@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#等式全排序"><span class="nav-number">1.</span> <span class="nav-text">等式全排序</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#排列："><span class="nav-number">1.1.</span> <span class="nav-text">排列：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#全排列："><span class="nav-number">1.2.</span> <span class="nav-text">全排列：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-3-4-5-6-7-8-9-110"><span class="nav-number">2.</span> <span class="nav-text">1 2 3 4 5 6 7 8 9 &#x3D; 110</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除不合法字符"><span class="nav-number">3.</span> <span class="nav-text">删除不合法字符</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#C-从string中删除所有的某个特定字符"><span class="nav-number">3.1.</span> <span class="nav-text">C++从string中删除所有的某个特定字符</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#分发礼物"><span class="nav-number">4.</span> <span class="nav-text">分发礼物</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">羊书</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
